from selenium import webdriver
import logging
# 配置日志
ft = '%(asctime)s - %(levelname)s [%(name)s] - (%(filename)s %(lineno)s) - %(message)s'
logging.basicConfig(level=logging.DEBUG, format=ft, filename='../logs/01.log', encoding='utf-8')
# 公共类，封装了页面操作的底层方法
class Base:
    def __init__(self):
        # 获取浏览器驱动
        self.driver = webdriver.Firefox()
        self.driver.maximize_window()
        self.driver.implicitly_wait(20)
        self.driver.get('http://127.0.0.1:8000/admin/')
    def base_find_element(self, loc): # 定位元素
        # *loc对元组进行解构
        return self.driver.find_element(*loc)
    def base_input(self, loc, text): # 往元素输入文本
        logging.debug(f'往元素{loc}中输入了文本{text}')
        el = self.base_find_element(loc)
        el.clear()
        el.send_keys(text)
    def base_click(self, loc): # 点击元素
        logging.debug(f'点击了元素{loc}')
        self.base_find_element(loc).click()
    def base_get_text(self, loc): # 获取元素的文本
        logging.debug(f'获取了{loc}元素的文本')
        return self.base_find_element(loc).text
    def base_close(self): # 关闭浏览器
        self.driver.quit()

if __name__ == '__main__':
    base = Base()
    base.base_close()